<?php
/**
 * Created by PhpStorm.
 * Author: 芸签cms www.yunqiancms.com
 * User: sun
 * Date: 2022/8/5
 * Time: 10:08 AM
 */
namespace app\frontend\modules\site\services;

use app\common\models\Page;
use app\common\models\Theme;

class PageService
{
    /**
     * 页面详情
     * @param $id
     * @return array
     */
    public function getDetail($id){
        $model = Page::site()->select()
            ->where('id',$id)
            ->first();
        $res = [];
        $res['info'] = $model;
        return $res;
    }

    /**
     * 合并seo信息
     * @param $siteInfo
     * @param $pageInfo
     * @return mixed
     */
    public function fmtSeoInfo($siteInfo,$pageInfo){
        $siteInfo['seo_title'] = $pageInfo['title'].'-'.$siteInfo['seo_title'];
        $siteInfo['seo_keywords'] = $pageInfo['keywords']?$pageInfo['keywords']:$siteInfo['seo_keywords'];
        $siteInfo['seo_description'] = $pageInfo['description']?$pageInfo['description']:$siteInfo['seo_description'];
        return $siteInfo;
    }

    public function getView($clientType,$view,$pageInfo){
        if($pageInfo['use_tpl']){
            if($clientType==Theme::TYPE_PC){
                if($pageInfo['pc_tpl']){
                    $view = $pageInfo['pc_tpl'];
                }
            }
            if($clientType==Theme::TYPE_H5){
                if($pageInfo['h5_tpl']){
                    $view = $pageInfo['h5_tpl'];
                }
            }
        }
        return $view;
    }
}